#ifndef SOLVER_H
#define SOLVER_H

#define WIN32 1

#include <opencv\cv.h>
#include <opencv\highgui.h>
#include <cmath>
#include <ctime>
#include <octave\oct.h>

using namespace std;
using namespace cv;

const double EPS = 1e-13;

class Solver {

	public:
		Solver();
		Solver(Mat &p_inputImage, Mat &p_mask);
		~Solver();

		Mat m_inputImage, m_mask, m_outputImage;
		SparseMatrix A;
		ColumnVector x1,x2,b1,b2;
		double *_Y0,*_I0,*_Q0,*_Y1,*_Y2,*_I1,*_I2,*_Q1,*_Q2;
		int m_row,m_col;
		clock_t m_timeBegin, m_timeEnd;

		int resize();
		int getRow(){return m_row;}
		int getCol(){return m_col;}
		int setInputImage(Mat &p);
		int setMaskImage(Mat &p);
		Mat& getOutputImage();
		Mat& solve(Mat &p_inputImage, Mat &p_mask, int p_isReducedSize);
		
		double getSolvingTime();

	private:

		Mat& solve();
		Mat& solveReduced(int p_isReducedSize);
		int mat2Array(Mat &m, double **p_y, double **p_i, double **p_q);
		int constructSparseMatrix();
		int constructColumnVectors();
		
		static double normalPdf ( double p_mean, double p_variance, double p_x );
		static int RGBnormalize ( double &r, double &g, double &b );
		static int YIQnormalize ( double &y, double &i, double &q );

};

#endif
